home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / fridgeSnackChar.lua < prev    next >
Text File  |  2004-01-29  |  11KB  |  370 lines

  1. -- fridge character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local fridge = getStateObjectFromID(msg.sender);
  6.         storeStateObject("fridge", fridge);
  7.     end )
  8.     
  9.     onExit(function(msg)
  10. --        local fridge = retrieveStateObject("fridge");
  11. --        getParent().unlockActionPoints(fridge);
  12. --        removeStateObject("fridge");
  13.     end )
  14.     
  15. --    onReturn(function(msg)
  16. --        -- back from subwalk
  17. --        print("onReturn global");
  18. --        setState(retrieveData("snackCommand"));
  19. --    end )
  20.  
  21.     -- open the fridge
  22.     state("open")
  23.     
  24.         onEnter(function(msg)
  25.             local fridge = retrieveStateObject("fridge");
  26.                 
  27.             if (fridge) then
  28.                 -- fridge does exist
  29.                 if (getParent().isOneActionPointLocked(fridge)) then
  30.                     -- action point is locked
  31.                     getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  32.                     sendMsg("emoThink", getParent().walkSO);
  33.                     exitStateMachine();
  34.                 else
  35.                     getParent().lockActionPoints(fridge);
  36.                 end
  37.             else
  38.                 -- fridge does not exist anymore
  39.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  40.                 sendMsg("emoThink", getParent().walkSO);
  41.                 exitStateMachine();
  42.             end
  43.             
  44.             freeHands(getParent());
  45.                 
  46.             -- create the cracker box
  47.             -- local crackerBox = fridge.createGameObject("CrackerBox");
  48.             -- start to open the fridge
  49.             startAnimation("openFridge");
  50.             fridge.startAnimation("fridge");
  51.             -- show the inside of the fridge
  52.             fridge.setChildEnable("fridgeIn", true);
  53.             -- show the cracker box
  54.             fridge.setChildEnable("CrackerBox", true);
  55.             -- send a delayed message for open sound
  56.             sendDelayedMsgThis("openSound", 800);
  57.             -- send a delayed message for attach
  58.             sendDelayedMsgThis("grabCrackerBox", 5000);
  59.             -- send a delayed message for close sound
  60.             sendDelayedMsgThis("closeSound", 6000);
  61.         end )
  62.     
  63.         onMsg("openSound", function(msg)
  64.             local fridge = retrieveStateObject("fridge");
  65.             fridge.playSound("fridgeOpen");
  66.             fridge.stopSound("fridgeLoop");
  67.         end)
  68.  
  69.         onMsg("grabCrackerBox", function(msg)
  70.             -- attach cracker box to left hand of character
  71.             local crackerBox = getParent().loadGameObject("StandardGO", "crackerBox");
  72.             storeStateObject("crackerBox", crackerBox);
  73.             getParent().attachLeftObjectHolder(crackerBox);
  74.             local fridge = retrieveStateObject("fridge");
  75.             fridge.playSound("fridgeTake");
  76.             fridge.setChildEnable("CrackerBox", false);
  77.         end)
  78.  
  79.         onMsg("closeSound", function(msg)
  80.             local fridge = retrieveStateObject("fridge");
  81.             fridge.playSound("fridgeClose");
  82.             fridge.stopSound("fridgeLoop");
  83.         end)
  84.  
  85.         onMsg("canceled", function(msg)
  86.             local crackerBox = getParent().getLeftHeldObject();
  87.             if (crackerBox) then
  88.                 getParent().detachLeftObjectHolder();
  89.                 crackerBox.deleteGameObject();
  90.                 -- hide the cracker box
  91.                 --fridge.setChildEnable("CrackerBox", false);
  92.             end
  93.             exitStateMachine();
  94.         end)
  95.  
  96.         onMsg("end", function(msg)
  97.             -- hide the inside of the fridge
  98.             local fridge = retrieveStateObject("fridge");
  99.             fridge.setChildEnable("fridgeIn", false);
  100.             
  101.             if testCancel() then
  102.                 sendMsgThis("canceled");
  103. --                -- detach cracker box if attached to left hand
  104. --                local crackerBox = getParent().getLeftHeldObject();
  105. --                if (crackerBox) then
  106. --                    getParent().detachLeftObjectHolder();
  107. --                    crackerBox.deleteGameObject();
  108. --                    -- hide the cracker box
  109. --                    --fridge.setChildEnable("CrackerBox", false);
  110. --                end
  111. --                exitStateMachine();
  112.             else
  113.                 --setState(retrieveData("snackCommand"));
  114.                 local actionPoint = getParent().findPointNear(1.0, 5.0);
  115.                 if (actionPoint) then
  116.                 
  117.                     if (walkToPointImmediate(actionPoint)) then
  118.                         local wsoContext = StateMachineContext();
  119.                         --wsoContext.storeStateObject("fridge", fridge);
  120.                         --queueStateMachine("fridgeSnackChar." .. retrieveData("snackCommand"), fridge, wsoContext);
  121.                         enterStateMachine("subwalk.walk");
  122.                     else
  123.                         print("no path found");
  124.                         sendMsgThis("canceled");
  125.                     end
  126.                                 
  127. --                    if (walkToActionPoint(actionPoint)) then
  128. --                        local wsoContext = StateMachineContext();
  129. --                        --wsoContext.storeStateObject("fridge", fridge);
  130. --                        queueStateMachine("fridgeSnackChar." .. retrieveData("snackCommand"), fridge, wsoContext);
  131. --                        exitStateMachine();
  132. --                    else
  133. --                        print("no path found");
  134. --                        sendMsgThis("canceled");
  135. --                    end
  136.  
  137.                 else
  138.                     print("no near free space found");
  139.                     setState(retrieveData("snackCommand"));
  140.                 end
  141.             end
  142.         end )
  143.         
  144.         onReturn(function(msg)
  145.             -- back from subwalk
  146.             print("onReturn open");
  147.             setState(retrieveData("snackCommand"));
  148.         end )
  149.             
  150.         
  151.         onExit(function(msg)
  152.             print("open exit");
  153.             local fridge = retrieveStateObject("fridge");
  154.             getParent().unlockActionPoints(fridge);
  155.             removeStateObject("fridge");
  156.         end )
  157.         
  158.     
  159.     -- eat a snack    
  160.     state("eatSnack")
  161.     
  162.         onEnter(function(msg)
  163.             
  164.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  165.                 exitStateMachine();
  166.             else
  167.                 local crackerBox = getParent().getLeftHeldObject();
  168.                 local eatSnack = getParent().startActivity("eatSnack", crackerBox);
  169.                 local length = getActivityLength(eatSnack);
  170.                 
  171.                 --flipPoseDirection(); -- animation ist wrong oriented
  172.                 
  173.                 sendDelayedMsgThis("complete", length);
  174.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  175.                 sendMsgThis("startLoop");
  176.                 
  177.                 crackerBox.buy(); -- pay money for food
  178.             end
  179.             
  180.         end )
  181.         
  182.         onExit(function(msg)
  183.             local crackerBox = getParent().getLeftHeldObject();
  184.             if (crackerBox) then
  185.                 print("deleting crackerBox")
  186.                 getParent().stopAllActivities(crackerBox);
  187.                 getParent().detachLeftObjectHolder();
  188.                 crackerBox.deleteGameObject();
  189.             end
  190.             
  191.             createTrash(0.1);
  192.             
  193.             --flipPoseDirection(); -- animation ist wrong oriented
  194.         end )
  195.         
  196.         
  197.         onMsg("startLoop", function(msg)
  198.             startAnimation("eatSnackLoop");
  199.             sendDelayedMsgThis("eatSound", 2200);
  200.             sendDelayedMsgThis("eatSound", 4500);
  201.         end )
  202.         
  203.         onMsg("eatSound", function(msg)
  204.             getParent().playSound("eat1");
  205.         end )
  206.                     
  207.         onMsg("testCancel", function(msg)
  208.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  209.                 exitStateMachine();
  210.             else
  211.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  212.             end
  213.         end )
  214.  
  215.         onMsg("complete", function(msg)
  216.             exitStateMachine()
  217.         end )
  218.         
  219.         onMsg("end", function(msg)
  220.             if (testCancel() or (getParent().getCondition(NEED_HUNGER) > 0.99)) then
  221.                 exitStateMachine();
  222.             else
  223.                 sendMsgThis("startLoop");
  224.             end
  225.         end )    
  226.         
  227.         
  228.     state("eatVegSnack")
  229.     
  230.         onEnter(function(msg)
  231.             
  232.             local crackerBox = getParent().getLeftHeldObject();
  233.             local eatSnack = getParent().startActivity("eatSnack", crackerBox);
  234.             local length = getActivityLength(eatSnack);
  235.             
  236.             sendDelayedMsgThis("complete", length);
  237.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  238.             sendMsgThis("startLoop");
  239.             
  240.             this.actionComplete();
  241.         end )
  242.         
  243.         onExit(function(msg)
  244.             local crackerBox = getParent().getLeftHeldObject();
  245.             getParent().stopAllActivities(crackerBox);
  246.             if (crackerBox) then
  247.                 getParent().detachLeftObjectHolder();
  248.                 crackerBox.deleteGameObject();
  249.             end
  250.         end )
  251.         
  252.         
  253.         onMsg("startLoop", function(msg)
  254.             startAnimation("eatSnackLoop");
  255.             sendDelayedMsgThis("eatSound", 2200);
  256.             sendDelayedMsgThis("eatSound", 4500);
  257.         end )
  258.         
  259.         onMsg("eatSound", function(msg)
  260.             getParent().playSound("eat1");
  261.         end )
  262.                     
  263.         onMsg("testCancel", function(msg)
  264.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  265.                 exitStateMachine();
  266.             else
  267.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  268.             end
  269.         end )
  270.  
  271.         onMsg("end", function(msg)
  272.             if (testCancel() or (getParent().getCondition(NEED_HUNGER) > 0.99)) then
  273.                 exitStateMachine();
  274.             else
  275.                 sendMsgThis("startLoop");
  276.             end
  277.         end )    
  278.         
  279.         
  280. --    -- eat a vegetarian snack    
  281. --    state("eatVegSnack")
  282. --    
  283. --        onEnter(function(msg)
  284. --            startAnimation("eatSnackLoop");
  285. --            local crackerBox = getParent().getLeftHeldObject();
  286. --            getParent().startActivity("eat", crackerBox);
  287. --            
  288. --            sendDelayedMsgThis("boxEmpty", 30000);
  289. --            this.actionComplete();
  290. --        end )
  291. --        
  292. --        onExit(function(msg)
  293. --            local crackerBox = getParent().getLeftHeldObject();
  294. --            getParent().stopAllActivities(crackerBox);
  295. --            if (crackerBox) then
  296. --                getParent().detachLeftObjectHolder();
  297. --                crackerBox.deleteGameObject();
  298. --            end
  299. --        end )
  300. --        
  301. --        
  302. --        onMsg("boxEmpty", function(msg)
  303. --            -- remove the cracker box
  304. --            print("boxEmpty");
  305. --            exitStateMachine();
  306. --        end )
  307. --            
  308. --        onMsg("end", function(msg)
  309. --            if (testCancel() or (getParent().getCondition(NEED_HUNGER) > 0.99)) then
  310. --                exitStateMachine();
  311. --            else
  312. --                startAnimation("eatSnackLoop");
  313. --                doSomething();
  314. --            end
  315. --        end )    
  316. --        
  317.         
  318. --    -- eat a snack    
  319. --    state("eatVegSnack")
  320. --    
  321. --        onEnter(function(msg)
  322. --            startAnimation("eatSnackLoop");
  323. --            local fridge = retrieveStateObject("fridge");
  324. --            getParent().startActivity("eatVegSnack", fridge)
  325. --            sendDelayedMsgThis("boxEmpty", 30000);
  326. --        end )
  327. --        
  328. --        onExit(function(msg)
  329. --            local fridge = retrieveStateObject("fridge");
  330. --            if (fridge) then getParent().stopAllActivities(fridge) end;
  331. --        end )
  332. --        
  333. --        
  334. --        onMsg("boxEmpty", function(msg)
  335. --            -- remove the cracker box
  336. --            print("boxEmpty");
  337. --            local crackerBox = getParent().getLeftHeldObject();
  338. --            if (crackerBox) then
  339. --                getParent().detachLeftObjectHolder();
  340. --                crackerBox.deleteGameObject();
  341. --                -- hide the cracker box
  342. --                --local fridge = retrieveStateObject("fridge");
  343. --                --fridge.setChildEnable("CrackerBox", false);
  344. --            end
  345. --            exitStateMachine();
  346. --        end )
  347. --        
  348. --    
  349. --        onMsg("end", function(msg)
  350. --            if (testCancel() or (getParent().getCondition(NEED_HUNGER) > 0.99)) then
  351. --                -- remove the cracker box
  352. --                local crackerBox = getParent().getLeftHeldObject();
  353. --                if (crackerBox) then
  354. --                    getParent().detachLeftObjectHolder();
  355. --                    crackerBox.deleteGameObject();
  356. --                    -- hide the cracker box
  357. --                    --local fridge = retrieveStateObject("fridge");
  358. --                    --fridge.setChildEnable("CrackerBox", false);
  359. --                end
  360. --                exitStateMachine();
  361. --            else
  362. --                startAnimation("eatSnackLoop");
  363. --                doSomething();
  364. --            end
  365. --        end )            
  366. --        
  367.         
  368.         
  369. endStateMachine()
  370.